/*
 * main.c
 */
#include "DSP281x_CpuTimers.h"
#include "DSP281x_SysCtrl.h"
#include "DSP281x_Device.h"
#include "os_cpu.h"

#define TASK_STK_SIZE      128u

OS_STK App_TaskStartStk[TASK_STK_SIZE];
OS_STK App_TaskLed0Stk[TASK_STK_SIZE];
OS_STK App_TaskLed1Stk[TASK_STK_SIZE];
OS_STK App_TaskLed2Stk[TASK_STK_SIZE];

static void App_TaskStart(void *p_arg);
static void App_TaskLed0(void *p_arg);
static void App_TaskLed1(void *p_arg);
static void App_TaskLed2(void *p_arg);
int main(void)
{
	InitSysCtrl();
	InitGpio();
	DINT;
	InitPieCtrl();
	IER=0x0000;
	IFR=0x0000;
	InitPieVectTable();
	InitCpuTimers();
	ConfigCpuTimer(&CpuTimer2,150,1000);
	IER=0xA000;
	EINT;
	ERTM;
	OSInit();
	OSTaskCreate(App_TaskStart,
				(void *)0,
				(OS_STK*)&App_TaskStartStk[0],
				2);
	OSStart();
	for(;;);

}
static void App_TaskStart(void *p_arg)
{
	StartCpuTimer2();
	OSTaskCreate(App_TaskLed0,
			(void *)0,
			(OS_STK*)&App_TaskLed0Stk[0],
			3);
	OSTaskCreate(App_TaskLed1,
			(void *)0,
			(OS_STK*)&App_TaskLed1Stk[0],
			4);
	OSTaskCreate(App_TaskLed2,
			(void *)0,
			(OS_STK*)&App_TaskLed2Stk[0],
			5);
	while (1)
	{
		OSTimeDlyHMSM(0,0,0,1);
	}
}

static void App_TaskLed0(void *p_arg)
{
	while(1)
	{
		OSTimeDlyHMSM(0,0,0,500);
		GpioDataRegs.GPATOGGLE.bit.GPIOA0=1;
	}
}

static void App_TaskLed1(void *p_arg)
{
	while(1)
	{
		OSTimeDlyHMSM(0,0,0,300);
		GpioDataRegs.GPATOGGLE.bit.GPIOA1=1;
	}
}

static void App_TaskLed2(void *p_arg)
{
	while(1)
	{
		OSTimeDlyHMSM(0,0,0,700);
		GpioDataRegs.GPATOGGLE.bit.GPIOA2=1;
	}
}
